﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;

namespace DeviceManagementIT.DevicesManager.DevicesManagement
{
    public partial class frmGroupDevice : DevExpress.XtraEditors.XtraForm
    {
        GroupDeviceBllOperation groupdevicebll = new GroupDeviceBllOperation();
        NHOMTHIETBI groupdevice;
        public frmGroupDevice()
        {
            InitializeComponent();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            List<NHOMTHIETBI> listgroup = new List<NHOMTHIETBI>();
            groupdevice=new NHOMTHIETBI();
            listgroup = groupdevicebll.GetRecordUnit(groupdevice);
            grCGroupDevice.DataSource = listgroup;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            groupdevice = new NHOMTHIETBI();
            if (grVGroupDevice.DataRowCount != 0)
            {
                groupdevice.NhomTBID = int.Parse(grVGroupDevice.GetFocusedRowCellDisplayText("NhomTBID"));
                groupdevice.TenNhomTB = grVGroupDevice.GetFocusedRowCellDisplayText("TenNhomTB");
                groupdevice.DienGiai = grVGroupDevice.GetFocusedRowCellDisplayText("DienGiai");
                string message = groupdevicebll.DeleteRecordUnit(groupdevice);
                MessageBox.Show(message, "Message");
                btnLoad.PerformClick();
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddGroupDevice m_frmAddGroupDevice = new frmAddGroupDevice();
            m_frmAddGroupDevice.Show();
        }

        private void txtSearch_EditValueChanged(object sender, EventArgs e)
        {
            groupdevice = new NHOMTHIETBI();
            groupdevice.TenNhomTB = txtSearch.Text;
            List<NHOMTHIETBI> listgroup = new List<NHOMTHIETBI>();
            listgroup = groupdevicebll.GetRecordUnit(groupdevice);
            grCGroupDevice.DataSource = listgroup;
        }
    }
}